package com.example.mapp.buildSql;

import org.apache.ibatis.jdbc.SQL;

import com.example.ext.entity.maintenance.ExtDebrisHalfMon;
import com.example.ext.entity.maintenance.ExtEscalatorHalfMon;
import com.example.ext.entity.maintenance.ExtHydpressHalfMon;
import com.example.ext.entity.maintenance.ExtTractionHalfMon;

/**
 * Created by douyx on 2017/11/2.
 */
public class MaintMappSql {

	/**
	 * 获取杂物电梯维保数据
	 * 
	 * @param debrisHalfMon
	 * @return
	 */
	public String findDebrisList(final ExtDebrisHalfMon debrisHalfMon) {

		String select = " d.* ";

		String table = " debris_half_mon as d left join elevator as e on d.elevator_num = e.elevator_num";
		String conditions = "  1=1 ";
		conditions += " and e.elevator_num = #{elevatorNum}";
		if (debrisHalfMon.getStatus() != null) {
			conditions += " and d.status = #{status}";
		}
		if (debrisHalfMon.getType() != null) {
			conditions += " and d.type = #{type}";
		}
		String finalConditions = conditions;
		return new SQL() {
			{
				SELECT(select);
				FROM(table);
				WHERE(finalConditions);
				ORDER_BY("d.id desc");
			}
		}.toString();
	}

	/**
	 * 获取自动扶梯 人行道维保数据
	 * 
	 * @param escalatorHalfMon
	 * @return
	 */
	public String findEscalatorList(final ExtEscalatorHalfMon escalatorHalfMon) {

		String select = " d.* ";

		String table = " escalator_half_mon as d left join elevator as e on d.elevator_num = e.elevator_num";
		String conditions = "  1=1 ";
		conditions += " and e.elevator_num = #{elevatorNum}";
		if (escalatorHalfMon.getStatus() != null) {
			conditions += " and d.status = #{status}";
		}
		if (escalatorHalfMon.getType() != null) {
			conditions += " and d.type = #{type}";
		}
		String finalConditions = conditions;
		return new SQL() {
			{
				SELECT(select);
				FROM(table);
				WHERE(finalConditions);
				ORDER_BY("d.id desc");
			}
		}.toString();
	}

	/**
	 * 获取液压电梯维保数据
	 * 
	 * @param hydpressHalfMon
	 * @return
	 */
	public String findHydpressList(final ExtHydpressHalfMon hydpressHalfMon) {

		String select = " d.* ";

		String table = " hydpress_half_mon as d left join elevator as e on d.elevator_num = e.elevator_num";
		String conditions = "  1=1 ";
		conditions += " and e.elevator_num = #{elevatorNum}";
		if (hydpressHalfMon.getStatus() != null) {
			conditions += " and d.status = #{status}";
		}
		if (hydpressHalfMon.getType() != null) {
			conditions += " and d.type = #{type}";
		}
		String finalConditions = conditions;
		return new SQL() {
			{
				SELECT(select);
				FROM(table);
				WHERE(finalConditions);
				ORDER_BY("d.id desc");
			}
		}.toString();
	}
	
	/**
	 * 获取曳引电梯维保数据
	 * 
	 * @param tractionHalfMon
	 * @return
	 */
	public String findTractionList(final ExtTractionHalfMon tractionHalfMon) {

		String select = " d.* ";

		String table = " traction_half_mon as d left join elevator as e on d.elevator_num = e.elevator_num";
		String conditions = "  1=1 ";
		conditions += " and e.elevator_num = #{elevatorNum}";
		if (tractionHalfMon.getStatus() != null) {
			conditions += " and d.status = #{status}";
		}
		if (tractionHalfMon.getType() != null) {
			conditions += " and d.type = #{type}";
		}
		String finalConditions = conditions;
		return new SQL() {
			{
				SELECT(select);
				FROM(table);
				WHERE(finalConditions);
				ORDER_BY("d.id desc");
			}
		}.toString();
	}
}
